package cn.rxmind.dlicense.core.decoder;

import cn.rxmind.dlicense.core.factory.DLicenseParamFactory;
import de.schlichtherle.license.*;
import de.schlichtherle.xml.GenericCertificate;


/**
 * 证书解密器
 *
 * @author renxin
 * @email renxinzhiliangzhi@163.com
 * @date 2021/4/16 4:30 下午
 */
public class DPublicCertLicenseDecoder extends LicenseManager implements DLicenseDecoder {

    private static final LicenseParam LICENSE_PARAM_4_CLIENT = DLicenseParamFactory.createLicenseParam4Client();

    public DPublicCertLicenseDecoder() {
        super(DPublicCertLicenseDecoder.LICENSE_PARAM_4_CLIENT);
    }

    @Override
    public Object decode(byte[] licenseBytes) throws Exception {

        final GenericCertificate certificate = getPrivacyGuard().key2cert(licenseBytes);
        getLicenseNotary().verify(certificate);
        return ((LicenseContent)certificate.getContent()).getExtra();
    }

}
